package logic

import (
	"context"
	"user_srv/user"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RegisterLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterLogic {
	return &RegisterLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RegisterLogic) Register(req *types.RegisterRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	register, err := l.svcCtx.UserSrv.Register(l.ctx, &user.RegisterRequest{
		Username: req.UserName,
		Password: req.Password,
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  "注册失败",
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "注册成功",
		Data: map[string]interface{}{
			"register": register,
		},
	}, nil
}
